package fragmentAppl;



import impl.AgentRef;

import java.util.ArrayList;
import java.util.Vector;

import tools.Debug;
import tools.FragmentState;
import tools.MMME;
import tools.MMMEDirectory;
import components.QuasiComponentRepresentations;


public class Representations extends QuasiComponentRepresentations {

	private ArrayList<MMME> requiredMMME;
	private ArrayList<MMME> providedMMME;
	
	private ArrayList<AgentRef> challengingFragment;
	private FragmentState currentState;
	
	private int criticity;
	private int processNumber;
	
	public Representations (){
		requiredMMME=new ArrayList<MMME>();
		providedMMME=new ArrayList<MMME>();
		criticity=0;
		currentState= FragmentState.Referenced;
		processNumber=0;
		//Debug.println("Representation ok");
	}


	public Vector<AgentRef> getChallengingFragments() {
		// TODO Auto-generated method stub
		Vector<AgentRef> challenging= new Vector<AgentRef>();
		
		return challenging;
	}

//
//	public int getCriticity() {
//		// TODO Auto-generated method stub
//		return criticity;
//	}
//
//
//	public Vector<MMMECharacteristics> getProvidedMMMECharacteristics() {
//		// TODO Auto-generated method stub
//		return providedMMMECharacteristics;
//	}
//
//
//	public Vector<MMMECharacteristics> getRequiredMMMECharacteristics() {
//		// TODO Auto-generated method stub
//		return requiredMMMECharacteristics;
//	}
//
//
//	public void setProvidedMMMECharacteristics(MMMECharacteristics mmme) {
//		// TODO Auto-generated method stub
//		for(int i=0;i<providedMMMECharacteristics.size();i++)
//			if(providedMMMECharacteristics.get(i).getId()==mmme.getId()){
//				providedMMMECharacteristics.set(i, mmme);
//				i=providedMMMECharacteristics.size();
//			}
//	}
//
//
//	public void setRequiredMMMECharacteristics(MMMECharacteristics mmme) {
//		// TODO Auto-generated method stub
//		for(int i=0;i<requiredMMMECharacteristics.size();i++)
//			if(requiredMMMECharacteristics.get(i).getId()==mmme.getId()){
//				requiredMMMECharacteristics.set(i, mmme);
//				i=requiredMMMECharacteristics.size();
//			}
//	}

	@Override
	public synchronized void setCriticity(int stimulation) {
		// TODO Auto-generated method stub
		criticity+=stimulation;
	}

	@Override
	public FragmentState getMyState() {
		// TODO Auto-generated method stub
		return currentState;
	}

	@Override
	public synchronized void setMyState(FragmentState state) {
		// TODO Auto-generated method stub
		currentState=state;
	}

	@Override
	public int getCriticity() {
		// TODO Auto-generated method stub
		return criticity;
	}

	@Override
	public ArrayList<MMME> getRequiredMMMECharacteristics() {
		// TODO Auto-generated method stub
		return requiredMMME;
	}

	@Override
	public ArrayList<MMME> getProvidedMMMECharacteristics() {
		// TODO Auto-generated method stub
		return providedMMME;
	}

	@Override
	public synchronized void setRequiredMMMECharacteristics(MMME mmme) {
		if(mmme==null){
			Debug.println(getId()+" : error  setRequiredMMMECharacteristics ");
		}
		else{
		for(int i=0;i<requiredMMME.size();i++)
			if(requiredMMME.get(i).getID().equals(mmme.getID())){
				requiredMMME.set(i, mmme);
				i=requiredMMME.size();
			}
		}
	}

	@Override
	public synchronized void setProvidedMMMECharacteristics(MMME mmme) {
		// TODO Auto-generated method stub
		if(mmme==null){
			Debug.println(getId().toString()+" error setProvidedMMMECharacteristics");
		}
		else{
			for(int i=0;i<providedMMME.size();i++)
				if(providedMMME.get(i).getID().equals(mmme.getID())){
					providedMMME.set(i, mmme);
					i=providedMMME.size();
				}
		}
		
	}


	@Override
	public int getProcessNumber() {
		return processNumber;
	}


	@Override
	public synchronized void setProcessNumber(int processNumber) {
		this.processNumber=processNumber;
	}


	@Override
	public Vector<String> getRequiredElements() {
		// TODO Auto-generated method stub
		Vector<String> elements=new Vector<String>();
		for (int i=0; i<requiredMMME.size();i++)
			elements.add(requiredMMME.get(i).getID());
		return null;
	}


	@Override
	public synchronized void initRep() {
		// TODO Auto-generated method stub
		setCriticity(getContextAdequacy());
		for(MMME m:getProvidedMMME())
			providedMMME.add(m);
		if(getRequiredMMME()!=null && getRequiredMMME().size()>0)
			for(MMME m:getRequiredMMME())
				requiredMMME.add(m);
		else Debug.println(getId()+" : no MMME is required");
	}

	

}
